<template>
  <div>
    <el-card>
      <h3>试卷名称:{{ pan.testinfo.sjname }}(总分{{ pan.testinfo.tscore }}) </h3>
      <p v-for="(i,index) of pan.que" :key="index">
        <span>题目:{{ i.title }} </span>
        <span>({{ i.score }}分)</span>
        <el-input v-model="i.answer" type="textarea" />
        <el-select v-model="i.defen" placeholder="请选择得分">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </p>
      <el-button type="primary" @click="tij">提交</el-button>
      <el-button type="primary" @click="fan">返回</el-button>
    </el-card>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      pan: {},
      options: [{
        value: 0,
        label: '0'
      }, {
        value: 5,
        label: '5'
      }, {
        value: 10,
        label: '10'
      }, {
        value: 15,
        label: '15'
      }, {
        value: 20,
        label: '20'
      }]
    }
  },
  computed: {},
  watch: {},
  async created() {
    var res = await this.http.get('/test/kao/', {
      params: { id: this.$route.query.id,
        page: 1,
        size: 3
      }
    })
    console.log(res)
    if (res.data.code == 200) {
      this.pan = res.data.data[0]
    }
  },
  mounted() {},
  methods: {
    fan() {
      this.$router.go(-1)
    },
    async tij() {
      var total = 0
      this.pan.que.forEach(element => {
        total += element.defen
      })
      var res = await this.http.put(`/test/kao/${this.$route.query.id}`, {
        tscore: total
      })
      if (res.data.code == 200) {
        this.$message.success('判卷完成')
        this.$router.go(-1)
      }
    }
  }
}
</script>
<style scoped>
    .el-card p{
        margin-top: 15px;
        margin-bottom: 15px;
    }
    .el-card .el-input{
        width: 600px;
    }
    .el-card .el-select{
        margin-top: 5px;
        width: 120px;
    }
</style>
